//
//  UIViewController+Helper.m
//  ChineseCollegeStudentsNetwork
//
//  Created by 魏苏扬 on 2018/8/9.
//  Copyright © 2018年 刘喆. All rights reserved.
//

#import "UIViewController+Helper.h"

@implementation UIViewController (Helper)
- (void)setupLeftWithTitle:(NSString *)title actionBlock:(void (^) (void))action {
    UIButton *b = [[UIButton alloc]init];
    [b setTitle:title forState:UIControlStateNormal];
    [b setTitleColor:SMCTHEME forState:UIControlStateNormal];
    b.titleLabel.font = [UIFont systemFontOfSize:17];
    CGSize size = [title sizeWithAttributes:@{NSFontAttributeName:b.titleLabel.font}];
    b.frame = CGRectMake(0, 0, ceilf(size.width), ceilf(size.height));
    [[b rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
        BLOCK_EXEC(action);
    }];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:b];
    self.navigationItem.leftBarButtonItems = @[item];
}


- (void)setupRightWithTitle:(NSString *)title actionBlock:(void (^) (void))action {
    UIButton *b = [[UIButton alloc]init];
    [b setTitle:title forState:UIControlStateNormal];
    [b setTitleColor:SMCTHEME forState:UIControlStateNormal];
    b.titleLabel.font = [UIFont systemFontOfSize:17];
    b.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
    CGSize size = [title sizeWithAttributes:@{NSFontAttributeName:b.titleLabel.font}];
    b.frame = CGRectMake(0, 0, ceilf(size.width), ceilf(size.height));
    [[b rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
        BLOCK_EXEC(action);
    }];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:b];
    self.navigationItem.rightBarButtonItems = @[item];
}

@end
